﻿using System;
namespace Producers.Rr.Xtee.Riik.Ee.Producer.Rr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="RR50Response", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RR50Response))]
    public class RR50ResponseSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IRR50Response clazz;
        
        public RR50ResponseSerializer(IRR50Response clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("surnu");
            if (clazz.Surnu!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute(">>>RR50Response>surnu>surnu", "http://producers.rr.xtee.riik.ee/producer/rr", clazz.Surnu.Count);
                for (int x = 0; ((clazz.Surnu != null) 
                            && (x < clazz.Surnu.Count)); x = (x + 1)) {
                    if (clazz.Surnu[x]!=null) {
                        Writer.WriteStartElement("surnu");
                        global::Xtee.Core.SerializationMetadata metaSurnu = this.GetMetaData(clazz.Surnu[x]);
                        Writer.WriteTypeAttribute(metaSurnu.TypeQualifiedName.Namespace, metaSurnu.TypeQualifiedName.Name);
                        metaSurnu.NewSerializer(clazz.Surnu[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Surnu");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="surnu") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR50Response>surnu");
                }
                clazz.Surnu = new System.Collections.Generic.List<RR50Response.ISurnuType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("surnu");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "surnu")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>RR50Response>surnu>surnu");
                        }
                        global::Xtee.Core.SerializationMetadata metaSurnu = this.GetMetaData<RR50Response.ISurnuType>(Reader, ">>>RR50Response>surnu>surnu", "http://producers.rr.xtee.riik.ee/producer/rr");
                        RR50Response.ISurnuType item = metaSurnu.NewEntity<RR50Response.ISurnuType>();
                        clazz.Surnu.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("surnu");
                            metaSurnu.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR50Response>surnu", Reader.LocalName);
            }
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>>RR50Response>surnu>surnu", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RR50Response.SurnuType))]
        public class SurnuTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected RR50Response.ISurnuType clazz;
            
            public SurnuTypeSerializer(RR50Response.ISurnuType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                Writer.WriteStartElement("surnu.Isikukood");
                if (clazz.SurnuIsikukood!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.SurnuIsikukood))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : SurnuIsikukood");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("surnu.Perenimi");
                if (clazz.SurnuPerenimi!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.SurnuPerenimi))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : SurnuPerenimi");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("surnu.Eesnimi");
                if (clazz.SurnuEesnimi!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.SurnuEesnimi))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : SurnuEesnimi");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("surnu.Surmakuup");
                if (clazz.SurnuSurmakuup!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.SurnuSurmakuup))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : SurnuSurmakuup");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("surnu.sdliik");
                if (clazz.Surnusdliik!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Surnusdliik))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Surnusdliik");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("surnu.sdnumber");
                if (clazz.Surnusdnumber!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Surnusdnumber))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Surnusdnumber");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("surnu.sdkuup");
                if (clazz.Surnusdkuup!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Surnusdkuup))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Surnusdkuup");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("surnu.sdasutus");
                if (clazz.Surnusdasutus!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Surnusdasutus))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Surnusdasutus");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("surnu.kmadliik");
                if (clazz.Surnukmadliik!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Surnukmadliik))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Surnukmadliik");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("surnu.kmadnumber");
                if (clazz.Surnukmadnumber!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Surnukmadnumber))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Surnukmadnumber");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("surnu.kmadkuup");
                if (clazz.Surnukmadkuup!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Surnukmadkuup))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Surnukmadkuup");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("surnu.kmadasutus");
                if (clazz.Surnukmadasutus!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Surnukmadasutus))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Surnukmadasutus");
                }
                Writer.WriteEndElement();
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="surnu.Isikukood") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR50Response>surnu>surnu>surnu.Isikukood");
                    }
                    clazz.SurnuIsikukood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("surnu.Isikukood")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR50Response>surnu>surnu>surnu.Isikukood", Reader.LocalName);
                }
                if (Reader.LocalName=="surnu.Perenimi") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR50Response>surnu>surnu>surnu.Perenimi");
                    }
                    clazz.SurnuPerenimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("surnu.Perenimi")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR50Response>surnu>surnu>surnu.Perenimi", Reader.LocalName);
                }
                if (Reader.LocalName=="surnu.Eesnimi") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR50Response>surnu>surnu>surnu.Eesnimi");
                    }
                    clazz.SurnuEesnimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("surnu.Eesnimi")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR50Response>surnu>surnu>surnu.Eesnimi", Reader.LocalName);
                }
                if (Reader.LocalName=="surnu.Surmakuup") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR50Response>surnu>surnu>surnu.Surmakuup");
                    }
                    clazz.SurnuSurmakuup = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("surnu.Surmakuup")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR50Response>surnu>surnu>surnu.Surmakuup", Reader.LocalName);
                }
                if (Reader.LocalName=="surnu.sdliik") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR50Response>surnu>surnu>surnu.sdliik");
                    }
                    clazz.Surnusdliik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("surnu.sdliik")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR50Response>surnu>surnu>surnu.sdliik", Reader.LocalName);
                }
                if (Reader.LocalName=="surnu.sdnumber") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR50Response>surnu>surnu>surnu.sdnumber");
                    }
                    clazz.Surnusdnumber = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("surnu.sdnumber")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR50Response>surnu>surnu>surnu.sdnumber", Reader.LocalName);
                }
                if (Reader.LocalName=="surnu.sdkuup") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR50Response>surnu>surnu>surnu.sdkuup");
                    }
                    clazz.Surnusdkuup = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("surnu.sdkuup")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR50Response>surnu>surnu>surnu.sdkuup", Reader.LocalName);
                }
                if (Reader.LocalName=="surnu.sdasutus") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR50Response>surnu>surnu>surnu.sdasutus");
                    }
                    clazz.Surnusdasutus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("surnu.sdasutus")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR50Response>surnu>surnu>surnu.sdasutus", Reader.LocalName);
                }
                if (Reader.LocalName=="surnu.kmadliik") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR50Response>surnu>surnu>surnu.kmadliik");
                    }
                    clazz.Surnukmadliik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("surnu.kmadliik")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR50Response>surnu>surnu>surnu.kmadliik", Reader.LocalName);
                }
                if (Reader.LocalName=="surnu.kmadnumber") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR50Response>surnu>surnu>surnu.kmadnumber");
                    }
                    clazz.Surnukmadnumber = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("surnu.kmadnumber")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR50Response>surnu>surnu>surnu.kmadnumber", Reader.LocalName);
                }
                if (Reader.LocalName=="surnu.kmadkuup") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR50Response>surnu>surnu>surnu.kmadkuup");
                    }
                    clazz.Surnukmadkuup = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("surnu.kmadkuup")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR50Response>surnu>surnu>surnu.kmadkuup", Reader.LocalName);
                }
                if (Reader.LocalName=="surnu.kmadasutus") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR50Response>surnu>surnu>surnu.kmadasutus");
                    }
                    clazz.Surnukmadasutus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("surnu.kmadasutus")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR50Response>surnu>surnu>surnu.kmadasutus", Reader.LocalName);
                }
            }
        }
    }
}
